"""
基本使用示例
"""
from k8s_deployment_extractor import K8sResourceAnalyzer

def main():
    # 创建分析器实例
    analyzer = K8sResourceAnalyzer()
    
    # 添加资源
    deployment = {
        "apiVersion": "apps/v1",
        "kind": "Deployment",
        "metadata": {
            "name": "example-deployment",
            "namespace": "default"
        },
        "spec": {
            "replicas": 3,
            "selector": {
                "matchLabels": {
                    "app": "example"
                }
            },
            "template": {
                "metadata": {
                    "labels": {
                        "app": "example"
                    }
                },
                "spec": {
                    "containers": [
                        {
                            "name": "example",
                            "image": "nginx:latest",
                            "ports": [
                                {
                                    "containerPort": 80
                                }
                            ]
                        }
                    ]
                }
            }
        }
    }
    
    service = {
        "apiVersion": "v1",
        "kind": "Service",
        "metadata": {
            "name": "example-service",
            "namespace": "default"
        },
        "spec": {
            "selector": {
                "app": "example"
            },
            "ports": [
                {
                    "port": 80,
                    "targetPort": 80
                }
            ],
            "type": "ClusterIP"
        }
    }
    
    # 添加资源
    analyzer.add_resources([deployment, service])
    
    # 执行健康检查
    health_result = analyzer.check_health()
    print("健康检查结果:", health_result)
    
    # 分析依赖关系
    dependency_result = analyzer.analyze_dependencies()
    print("依赖分析结果:", dependency_result)
    
    # 导出报告
    analyzer.export_health_report("health_report.yaml", "yaml")
    analyzer.export_dependency_report("dependency_report.yaml", "yaml")
    
    # 获取资源详细信息
    deployment_details = analyzer.get_resource_details("default/example-deployment")
    print("Deployment详情:", deployment_details)
    
    # 获取依赖关系
    service_dependencies = analyzer.get_resource_dependencies("default/example-service")
    print("Service依赖:", service_dependencies)
    
    # 获取可用格式
    available_formats = analyzer.get_available_formats()
    print("可用格式:", available_formats)
    
    # 更新配置
    new_config = {
        "report": {
            "formats": ["yaml", "json", "html"]
        }
    }
    analyzer.update_config(new_config)

if __name__ == "__main__":
    main() 